package com.hns.phone.master.web;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysRoleEntity;
import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.domain.GridPage;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.common.web.BaseController;
import com.hns.frame.mybatis.Pagination;
import com.hns.phone.master.service.PhoneDataReportService;
import com.hns.phone.master.vo.PhoneDataReportInfoVo;
import com.hns.phone.master.vo.PhoneDataReportParamsVo;
import com.hns.phone.master.vo.PhoneLineBhvDataVo;

/**
 * 数据报告controller
 * @author:zhangy
 * @email:zhangyu2222z@sina.cn
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/api/phoneDataReport")
public class PhoneDataReportController extends BaseController {
	
	@Autowired
	private PhoneDataReportService phoneDataReportService;
	
	/**
	 * 获取数据报告
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@ResponseBody
	@RequestMapping("/getDataReportInfo")
	public Object getDataReportInfo(String date){
		SysUserEntity user = this.getPhoneCurrentUser();
		ArrayList<SysRoleEntity> roleList = (ArrayList<SysRoleEntity>) request.getSession().getAttribute("CURRENTUSERROLELIST");
		PhoneDataReportInfoVo dataReportInfo = phoneDataReportService.getDataReportInfo(date, roleList,user);
		return this.getReturnResult(dataReportInfo);
	}
	
	/**
	 * 获取历史数据报告
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@ResponseBody
	@RequestMapping("/getDataHistoryReport")
	public Object getDataHistoryReport(){
		SysUserEntity user = this.getPhoneCurrentUser();
		ArrayList<SysRoleEntity> roleList = (ArrayList<SysRoleEntity>) request.getSession().getAttribute("CURRENTUSERROLELIST");
		Pagination page = phoneDataReportService.getDataHistoryReport(roleList,user);
		GridPage grid = new GridPage(page);
		return this.getReturnResult(grid);
	}
	
	/**
	 * 线路数据报告
	 * @param date
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@ResponseBody
	@RequestMapping("/getLineDataReport")
	public Object getLineDataReport(String date){
		ArrayList<SysRoleEntity> roleList = (ArrayList<SysRoleEntity>) request.getSession().getAttribute("CURRENTUSERROLELIST");
		Pagination page = phoneDataReportService.getLineDataReport(date, roleList);
		GridPage grid = new GridPage(page);
		return this.getReturnResult(grid);
	}
	
	/**
	 * 线路故障数据
	 * @param params
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@ResponseBody
	@RequestMapping("/getLineFaultData")
	public Object getLineFaultData(CommonParamsVo params){
		ArrayList<SysRoleEntity> roleList = (ArrayList<SysRoleEntity>) request.getSession().getAttribute("CURRENTUSERROLELIST");
		PhoneDataReportInfoVo phoneDataReportInfoVo = phoneDataReportService.getLineFaultData(params, roleList);
		return this.getReturnResult(phoneDataReportInfoVo);
	}
	
	/**
	 * 线路行为汇总
	 * @param params
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@ResponseBody
	@RequestMapping("/getLineBhvData")
	public Object getLineBhvData(CommonParamsVo params){
		ArrayList<SysRoleEntity> roleList = (ArrayList<SysRoleEntity>) request.getSession().getAttribute("CURRENTUSERROLELIST");
		params.setBeginTime(params.getDate());
		params.setEndTime(params.getDate() + " 23:59:59");
		
		List<PhoneLineBhvDataVo> list = phoneDataReportService.getLineBhvData(params, roleList);
		return this.getReturnResult(list);
	}
	
	/**
	 * 线路能耗汇总
	 * @param params
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@ResponseBody
	@RequestMapping("/getLineEnergyData")
	public Object getLineEnergyData(PhoneDataReportParamsVo params){
		ArrayList<SysRoleEntity> roleList = (ArrayList<SysRoleEntity>) request.getSession().getAttribute("CURRENTUSERROLELIST");
		PhoneLineBhvDataVo phoneLineBhvDataVo = phoneDataReportService.getLineEnergyData(params, roleList);
		return this.getReturnResult(phoneLineBhvDataVo);
	}
	
}
